﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dao;

namespace Web.Page
{
    public partial class CPBZX_Query : BasePage
    {
        protected string wllxbh;
        protected string wlsxbh;
        Guid  bh;
        ZL_CPBZX_Dao dao = new ZL_CPBZX_Dao();


        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            wllxbh = Request.QueryString["wllxbh"];
            wlsxbh = Request.QueryString["wlsxbh"];
            try
            {
                bh = Guid.Parse(Request.QueryString["bh"]);
            }
            catch
            {
 
            }
            if (!IsPostBack)
            {
                string vpath = Request.QueryString[WLTree.VPATH];
                if (vpath != null)
                {
                    Cache.Insert(WLTree.VPATH, vpath);
                }
                this.lbTitle.Text = "产品包装箱";
                BindGridview();
                BindGridview2();
            }
        }

        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            BindGridview();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindGridview();
            SavePageIndex(e.NewPageIndex);
        }

        private void BindGridview()
        {
            GridView1.PageIndex = RestorePageIndex();
            List<ZL_CPBZX> list = dao.QueryAll();
            this.GridView1.DataSource = list;
            this.GridView1.DataBind();
        }

        private void BindGridview2()
        {
            GridView1.PageIndex = RestorePageIndex();
            List<ZL_CPBZX> list = dao.QueryAll(bh);
            this.GridView1.DataSource = list;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    ((ImageButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick ", "return   confirm( '确定删除？ ') ");
            //}
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
            int result = dao.Delete(id);
            if (result == 1)
            {
                lbResult.Text = "删除成功";
                BindGridview();
                Cache.Insert(WLTree.LEVEL, WLTree.WLSXZ);

                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "onSuccess", "<script type='text/javascript'>parent.refresh('tree');</script>", false);
            }
        }

        protected void btnAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (wllxbh != null && wlsxbh != null)
            {
                Response.Redirect(string.Format("CPBZX_Add.aspx?wllxbh={0}&wlsxbh={1}", wllxbh, wlsxbh));
            }
            else
            {
                Response.Redirect("~/Page/CPBZX_Add.aspx");
            }
        }
    }
}
   
